from wand.image import Image
import sys

def convert(filename):
    """
    将pdf文件转换为同名的png文件
    :param filename:    pdf文件路径
    :return:            生成的同名png文件
    :param filename:
    :return:
    """
    with(Image(filename=filename, resolution=255)) as source:
        images = source.sequence
        pages = len(images)
        for i in range(pages):
            n = i + 1
            newfilename = filename[:-4] + str(n) + '.png'
            Image(images[i]).save(filename=newfilename)


if __name__ == '__main__':
    if len(sys.argv) != 2:
        print("Error：请正确输入参数 ")
        print("pdf2png 文件路径")
    else:
        convert(sys.argv[1])